package com.qz.center.file.server.service.impl;

import com.qz.center.file.server.common.FileUtils;
import com.qz.center.file.server.service.FileService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @author gbx
 */
@Service
public class FileServiceImpl implements FileService {
    @Override
    public String uploadFile(MultipartFile file) {
        return FileUtils.saveFile(file);
    }

    @Override
    public String uploadFiles(List<MultipartFile> files) {
        StringBuffer sb = new StringBuffer();
        for (MultipartFile file:files){
            String url = FileUtils.saveFile(file);
            if (StringUtils.isBlank(url)){
                return null;
            }
            sb.append(url + ",");
        }
        sb.deleteCharAt(sb.length()-1);
        return sb.toString();
    }
}
